
import peripheralfile from '@ohos.peripheralfile';



export default class USBDeriveModel {

    //单例
    static shareInstance():USBDeriveModel{
        if (!globalThis.USBDeriveModel) {
            globalThis.USBDeriveModel = new USBDeriveModel()
        }
        return globalThis.USBDeriveModel
    }

    //删除文件
    deleteFile(file,callback){
        peripheralfile.delete({
            uri: file,
            success: ()=> {
                callback(true)

            },
            fail: function(data, code) {
                callback(false)
            },
        });
    }

    //添加文件夹
    mkdir(uri,callback) {
        peripheralfile.mkdir({
            uri:uri,
            success: ()=> {
//                this.getDataList()
                callback(true)
            },
            fail: (data, code)=> {
                callback(false)
            },
        });
    }

    //移除文件夹
    rmdir(file,callback) {
        peripheralfile.rmdir({
            uri: file,
            success: ()=> {
//                this.getDataList()
                callback(true)
            },
            fail: (data, code)=> {
                callback(false)
            },
        });
    }

    //获取目录
    async getDataList(path,callback) {
        await peripheralfile.list({
            uri: path,
            success: (data) =>{
//                this.arr = data.fileList
                callback(undefined,data.fileList)
            },
            fail: (data, code) =>{
                callback(code,undefined)
            },
        });
    }

    //复制
    async copy(uri,des,callback) {
        peripheralfile.copy({
            srcUri: uri,
            dstUri: des,
            success: function(uri) {
                callback(true)

            },
            fail: function(data, code) {
                callback(false)
            },
        });
    }

    //移动
    async move(uri,des,callback) {
        peripheralfile.move({
            srcUri: uri,
            dstUri: des,
            success: function(uri) {
                callback(true)
            },
            fail: function(data, code) {
                callback(false)
            },
        });
    }
}